//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a sample for BCGControlBar Library Professional Edition
// Copyright (C) 1998-2016 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//*******************************************************************************
//
// ChartLine3DView.cpp : implementation file
//

#include "stdafx.h"
#include "bcgpchartexample.h"
#include "ChartLine3DView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChartLine3DView

IMPLEMENT_DYNCREATE(CChartLine3DView, CBCGPChartExampleView)

CChartLine3DView::CChartLine3DView()
	: CBCGPChartExampleView(CChartLine3DView::IDD)
{
	//{{AFX_DATA_INIT(CChartLine3DView)
	m_bShowDataLabels = FALSE;
	m_nDataLabelAngle = 3;
	m_nTransparency = 10;
	m_nLineThickness = 1;
	m_bShowWalls = TRUE;
	m_bThickWalls = TRUE;
	//}}AFX_DATA_INIT
}

CChartLine3DView::~CChartLine3DView()
{
}

void CChartLine3DView::DoDataExchange(CDataExchange* pDX)
{
	CBCGPChartExampleView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChartLine3DView)
	DDX_Control(pDX, IDC_LINE_THICKNESS, m_wndLineThickness);
	DDX_Control(pDX, IDC_ROTATE, m_wndRotate);
	DDX_Control(pDX, IDC_DATA_LABEL_ANGLE, m_wndDataLabelAngle);
	DDX_Control(pDX, IDC_CHART, m_wndChart);
	DDX_Check(pDX, IDC_DATA_LABELS, m_bShowDataLabels);
	DDX_CBIndex(pDX, IDC_DATA_LABEL_ANGLE, m_nDataLabelAngle);
	DDX_Control(pDX, IDC_TRANSPARENCY, m_wndTransparency);
	DDX_Slider(pDX, IDC_TRANSPARENCY, m_nTransparency);
	DDX_Slider(pDX, IDC_LINE_THICKNESS, m_nLineThickness);
	DDX_Check(pDX, IDC_SHOW_WALLS, m_bShowWalls);
	DDX_Control(pDX, IDC_THICK_WALLS, m_wndThickWalls);
	DDX_Check(pDX, IDC_THICK_WALLS, m_bThickWalls);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChartLine3DView, CBCGPChartExampleView)
	//{{AFX_MSG_MAP(CChartLine3DView)
	ON_BN_CLICKED(IDC_DATA_LABELS, OnUpdateChart)
	ON_BN_CLICKED(IDC_ROTATE, OnRotate)
	ON_WM_HSCROLL()
	ON_CBN_SELENDOK(IDC_DATA_LABEL_ANGLE, OnUpdateChart)
	ON_BN_CLICKED(IDC_SHOW_WALLS, OnUpdateChart)
	ON_BN_CLICKED(IDC_THICK_WALLS, OnUpdateChart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChartLine3DView diagnostics

#ifdef _DEBUG
void CChartLine3DView::AssertValid() const
{
	CBCGPChartExampleView::AssertValid();
}

void CChartLine3DView::Dump(CDumpContext& dc) const
{
	CBCGPChartExampleView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChartLine3DView message handlers

void CChartLine3DView::OnInitialUpdate() 
{
	CBCGPChartExampleView::OnInitialUpdate();
	
	if (m_bIsReady)
	{
		return;
	}

	m_bIsReady = TRUE;

	m_wndTransparency.SetRange(0, 100, TRUE);
	m_wndLineThickness.SetRange(1, 10, TRUE);

	m_wndRotate.GetRotationObject()->SetAutorepeatMode(100);
	m_wndRotate.GetRotationObject()->SetColorTheme(CBCGPRotationObject::BCGP_COLOR_THEME_VISUAL_MANAGER);

	m_wndRotate.GetRotationObject()->EnableFlatIcons();

	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	pChart->ShowAxisIntervalInterlacing(BCGP_CHART_X_PRIMARY_AXIS, FALSE);
	pChart->ShowAxisIntervalInterlacing(BCGP_CHART_Y_PRIMARY_AXIS);

	BCGPChartType type = 
		(m_Feature == CDemoFeature::BCGP_StackedLine || m_Feature == CDemoFeature::BCGP_StackedLineSpline) ? BCGP_CT_STACKED :
		(m_Feature == CDemoFeature::BCGP_StackedLine100) ? 
		BCGP_CT_100STACKED : BCGP_CT_SIMPLE;

	pChart->SetChartType(BCGPChartLine3D, type);

	pChart->SetChartTitle(_T("Furniture Sales"));

	CBCGPChartSeries* pSeries1 = pChart->CreateSeries(_T("Tables"));
	CBCGPChartSeries* pSeries2 = pChart->CreateSeries(_T("Chairs"));
	CBCGPChartSeries* pSeries3 = pChart->CreateSeries(_T("Cabinets"));

	pSeries1->AddDataPoint(m_arYears[4], 5.);
	pSeries1->AddDataPoint(m_arYears[3], 8.);
	pSeries1->AddDataPoint(m_arYears[2], 12.);
	pSeries1->AddDataPoint(m_arYears[1], 13.);
	pSeries1->AddDataPoint(m_arYears[0], 7.);

	pSeries2->AddDataPoint(9.);
	pSeries2->AddDataPoint(10.);
	pSeries2->AddDataPoint(14.);
	pSeries2->AddDataPoint(11.);
	pSeries2->AddDataPoint(23.);

	pSeries3->AddDataPoint(11.);
	pSeries3->AddDataPoint(7.);
	pSeries3->AddDataPoint(16.);
	pSeries3->AddDataPoint(10.);
	pSeries3->AddDataPoint(13.);

	CBCGPChartAxis* pYAxis = pChart->GetChartAxis(BCGP_CHART_Y_PRIMARY_AXIS);
	ASSERT_VALID(pYAxis);

	pYAxis->m_majorTickMarkType = CBCGPChartAxis::TMT_CROSS;
	pYAxis->m_minorTickMarkType = CBCGPChartAxis::TMT_CROSS;

	CBCGPChartAxis* pXAxis = pChart->GetChartAxis(BCGP_CHART_X_PRIMARY_AXIS);
	ASSERT_VALID(pXAxis);

	pXAxis->m_majorTickMarkType = CBCGPChartAxis::TMT_CROSS;
	pXAxis->m_minorTickMarkType = CBCGPChartAxis::TMT_CROSS;

	OnUpdateChart();
}

void CChartLine3DView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CBCGPChartExampleView::OnHScroll(nSBCode, nPos, pScrollBar);

	if (pScrollBar != NULL)
	{
		OnUpdateChart();
	}
}

void CChartLine3DView::OnUpdateChart() 
{
	UpdateData();

	m_wndDataLabelAngle.EnableWindow(m_bShowDataLabels);

	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	double dblDataLabelAngle = (m_nDataLabelAngle - 2) * 45;

	pChart->ShowDataLabels(m_bShowDataLabels, TRUE, TRUE, dblDataLabelAngle);

	pChart->SetThemeOpacity(100 - m_nTransparency);

	for (int i = 0; i < pChart->GetSeriesCount(); i++)
	{
		CBCGPChartSeries* pSeries = pChart->GetSeries(i);
		ASSERT_VALID(pSeries);
	
		pSeries->SetDataPoint3DLineThickness(m_nLineThickness);
	}

	DWORD dwoFlags = CBCGPChartDiagram3D::DWO_OUTLINE_ALL;

	// Draw walls and floor:
	if (m_bShowWalls)
	{
		dwoFlags |= (CBCGPChartDiagram3D::DWO_DRAW_ALL_WALLS | CBCGPChartDiagram3D::DWO_DRAW_FLOOR);
	}

	m_wndThickWalls.EnableWindow(m_bShowWalls);

	pChart->GetDiagram3D()->SetDrawWallOptions((CBCGPChartDiagram3D::DrawWallOptions)dwoFlags);
	pChart->GetDiagram3D()->SetThickWallsAndFloor(m_bShowWalls && m_bThickWalls);

	pChart->SetDirty();
	pChart->Redraw();
}

void CChartLine3DView::OnRotate() 
{
	RotateChart(m_wndRotate.GetRotationObject()->GetClicked());
}
